#include <stdio.h>
#include <malloc.h>
#include <limits.h>

int max_seq(int *,unsigned,unsigned*,unsigned*);

int main(void){
//printf("INT_MIN:%d\n",INT_MIN);
	unsigned ns;
	scanf("%u",&ns);
	int *num=malloc(sizeof(int)*ns);
	for(int i=0;i<ns;i++)
		scanf("%d",&num[i]);
	unsigned start,end;
	int max=max_seq(num,ns,&start,&end);
	if( 0 > max){
		printf("0 %d %d",num[0],num[ns-1]);
	}else{
		printf("%d %u %d",max,num[start],num[end]);
	}
	return 0;
}


int max_seq(int *num,unsigned num_size,unsigned *i,unsigned *j){
	int max=INT_MIN;
	int group_v=0;
	unsigned s=0,e=0,max_i=0,max_j=0;
	for(int i=0;i<num_size;i++){
		if ( group_v < 0 ){
			group_v=0;
			s=e=i;
		}
		group_v+=num[i];
		if ( group_v > max ){
			max=group_v;
			e=i;
			max_i=s;
			max_j=e;
		}
	}
	*i=max_i;
	*j=max_j;
	return max;
}
